const Service = require('egg').Service

class HomeService extends Service {
    async find(id) {
        const userInfo = await this.ctx.model.Users.findOne({
            where: {
                'ID': id
            }
        })

        return userInfo
    }

    async getIdAllCount(getUserInfo){
        const noteIdAll=await this.ctx.model.Notes.findAndCountAll({
            where: {
                userID: getUserInfo.ID
            }
        })

        return noteIdAll
    }

    async getNote(getUserInfo,page) {
        const notes = await this.ctx.model.Notes.findAll({
            where: {
                userID: getUserInfo.ID
            },
            order: [['ID', 'DESC']],
            limit: 5,
            offset: (page - 1) * 5
        })

        return notes
    }

    async getAllCount() {
        const noteAll = await this.ctx.model.Notes.findAndCountAll()
        return noteAll
    }

    async getAllNote(page) {
        const noteAll = await this.ctx.model.Notes.findAll({
            order: [['ID', 'DESC']],
            limit: 5,
            offset: (page - 1) * 5
        })
        return noteAll
    }
}

module.exports = HomeService